// ---------------------------------------------------------------------------

#pragma hdrstop

#include <tchar.h>
#include <iostream.h>

// ---------------------------------------------------------------------------

#pragma argsused

// ---------------------------------------------------------------------------
int income; // Income money
int expens; // Expens money
int amount; // Your money

// ---------------------------------------------------------------------------
int showMenu(void); // Output Menu
void selectOp(int choose); // Select Operations
void incomeOp(void); // Income Operation
void expenseOp(void); // Expense Operation
void reportOp(void); // Report Operation
bool exitOp(void);

// Exit Operation
// ---------------------------------------------------------------------------
int _tmain(int argc, _TCHAR* argv[]) {
	int choose;
	bool exit = false;
	do {
		choose = showMenu();
		selectOp(choose);
	}
	while (!(exit = exitOp()));
	return 0;
}

// ---------------------------------------------------------------------------
int showMenu(void) {
	cout << "Select the operation:" << endl;
	int menu_choose = 0;
	int num_menu;
	do {
		num_menu = 0;
		cout << "[" << ++num_menu << "] Income" << endl;
		cout << "[" << ++num_menu << "] Expense" << endl;
		cout << "[" << ++num_menu << "] Report" << endl;
		cout << "[" << ++num_menu << "] Exit" << endl;
		cin >> menu_choose;
	}
	while (menu_choose <= 0 || menu_choose > num_menu);
	return menu_choose;
}

void selectOp(int choose) {
	switch(choose) {
	case 1:
		incomeOp();
		break;
	case 2:
		expenseOp();
		break;
	case 3:
		reportOp();
	case 4:
		exit;
		break;
	}
}

void incomeOp(void) {
	cout << "You choose \"Income\"" << endl;
	cout << "Enter the amount of income: ";
	cin >> ::income;
}

void expenseOp(void) {
	cout << "You choose \"Expense\"" << endl;
	cout << "Enter the amount of expense: ";
	cin >> ::expens;
}

void reportOp(void) {
	cout << "You choose \"Report\"" << endl;
	::amount = ::income - ::expens;
	cout << "You have " << ::amount << " money" << endl;
}

bool exitOp(void) {
	char choose;
	cout << "Exit? (Y - yes; N - no)" << endl;
	cin >> choose;
	if ((choose == 'Y') || (choose == 'y'))
		return true;
	else
		return false;
}
